package time;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class TimeTest {
    private static DateFormat mFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
    private static DateFormat mFormat1 = new SimpleDateFormat("HH:mm:yy:MM:dd", Locale.getDefault());

    public static void main(String[] args) {
        //test001();
        test002();
    }

    /**
     *@Author: caoxiabo on 2019/12/17 11:13
     *@Description: 华晨主板
     */
    private static void test001() {
        Calendar calendar = new GregorianCalendar();
        calendar.add(calendar.DATE,0);
        Date date=calendar.getTime();
        String dateString = mFormat1.format(date);
        System.out.println("dateString:"+dateString);
        String[] times1 = dateString.split(":");
        int mYearOn = Integer.parseInt(times1[2]);
        int mMonthOn = Integer.parseInt(times1[3]);
        int mDateOn = Integer.parseInt(times1[4]);
        String timeOn = "08-21";
        String[] times = timeOn.split("-");
        int mHourOn = Integer.parseInt(times[0]);
        int mMinuteOn = Integer.parseInt(times[1]);
        String boottime = "1,0,0," + mHourOn + "," + mMinuteOn+ "," + mYearOn + "," + mMonthOn + "," + mDateOn;
        System.out.print("boottime:"+boottime);
    }

    /**
     *@Author: caoxiabo on 2019/12/17 11:16
     *@Description: 华芯智控主板
     */
    private static void test002() {
        Date date=new Date();//取时间
        System.out.println("date:"+date.getTime());
        String dateString = mFormat.format(date);
        String powerOff = dateString.concat("-"+ "22-00");
        System.out.println("powerOff:"+powerOff);

        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE,1);//把日期往后增加一天.整数往后推,负数往前移动
        date=calendar.getTime(); //这个时间就是日期往后推一天的结果
        dateString = mFormat.format(date);
        String powerOn = dateString.concat("-"+ "07-00");
        System.out.println("powerOn:"+powerOn);

        SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
        try {
            long powerOFF = formatter1.parse(powerOff).getTime();
            System.out.println("毫秒值："+powerOFF);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
